package com.zhangliuliu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhangliuliu.bean.UserBean;
import com.zhangliuliu.dao.IUserDao;
import com.zhangliuliu.service.IUserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
@Service
@Transactional
public class IUserServiceImpl extends ServiceImpl <IUserDao, UserBean> implements IUserService {


    @Override
    public void addUser(UserBean userBean) {
       save(userBean);

    }

    @Override
    public void delUser(int userId) {
        removeById(userId);
    }

    @Override
    public void updateUser(int userId, String userPwd, String power) {
        UserBean user = new UserBean();
         user.setUserId(userId);
        user.setUserPwd(userPwd);
        user.setUserPower(power);
        this.updateById(user);


    }

    @Override
    public IPage<UserBean> cutByPower(int pageNo, int pageSize, String power) {
       Page<UserBean> Page = new Page<>(pageNo,pageSize);
        QueryWrapper wrapper = new QueryWrapper();
       if (power!=null && !power.equals("")){
           wrapper.eq("user_power",power);
       }
       IPage<UserBean> page = this.page(Page, wrapper);
       return page;

    }

    @Override
    public UserBean login(String userName, String userPwd) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("user_name",userName);
        wrapper.eq("user_pwd",userPwd);
        return getOne(wrapper);
    }

    @Override
    public IPage<UserBean> cut(int pageNo, int pageSize) {
         Page<UserBean> Page = new Page<>(pageNo, pageSize);
        return this.page(Page,null);
    }


}

